using System;
using System.Collections.Generic;
using System.Text;
using Presentation.Contracts;
using Task.Contracts;
using DataAccess;
using Globals;
using Task;
using System.Data;
using System.Web;

namespace Presentation
	{
	public sealed class MyForumsPresenter
		{
		#region Members

        /// <summary>
        /// Instance of view.
        /// </summary>
        private IMyForumsView view;

        /// <summary>
        /// Simple galleryTask.
        /// </summary>
        private IForumTask task;

        #endregion Members

        #region Construction/Finalization

        /// <summary>
        /// Initializes a new instance of the <see cref="AddForumPresenter"/> class.
        /// </summary>
        /// <param name="view">The view.</param>
		public MyForumsPresenter(IMyForumsView view)
        {
            this.view = view;
            task = new ForumTask();
        }

        #endregion Construction/Finalization

        #region Public Methods

        /// <summary>
        /// Initializes view.
        /// </summary>
        public void Initialize()
        {
			List<DataAccess.forum> tmpList = task.GetForumsByNewestCommentForUser(view.MyForumsStartIndex, 4, view.LoggedUserID);
			DataTable dt = new DataTable();
			dt.Columns.Add("name", typeof(string));
			dt.Columns.Add("id", typeof(string));
			foreach (DataAccess.forum f in tmpList)
				{
				DataRow dr = dt.NewRow();
				dr[0] = f.name + " (" +task.CountTopicsInForum(f.id).ToString()+")";
				dr[1] = f.id.ToString();
				dt.Rows.Add(dr);
				}
			view.ShowMyForums(dt);

			tmpList = task.GetOwnedForums(view.MyOwnerForumsStartIndex, 4, view.LoggedUserID);
			dt = new DataTable();
			dt.Columns.Add("name", typeof(string));
			dt.Columns.Add("id", typeof(string));
			foreach (DataAccess.forum f in tmpList)
				{
				DataRow dr = dt.NewRow();
				dr[0] = f.name + " (" + task.CountTopicsInForum(f.id).ToString() + ")";
				dr[1] = f.id.ToString();
				dt.Rows.Add(dr);
				}
			view.ShowMyOwnerForums(dt);
			
			
			/*
			view.ForumDescription = string.Empty;
            view.ForumName = string.Empty;
			view.ShowForums(galleryTask.GetForumsByNewestCommentForUser(0,10,2));
			view.ShowComments(galleryTask.GetComments(3,1,3));
			 */ 

        }

		public void PageMyOwnerForums()
			{
			view.PageMyOwnerForums(4, task.GetMyOwnerForumsCount(view.LoggedUserID));
			}

		public void PageMyForums()
			{
			view.PageMyForums(4, task.GetMyForumsCount(view.LoggedUserID));
			}

        /// <summary>
        /// Adds the new forum.
        /// </summary>
		///
        public void AddNewForum()
        {
            task.AddForum(GetForumObjectFromView(),view.LoggedUserID);
        }

        #endregion Public Methods

        #region Private Methods

        /// <summary>
        /// Gets the forum object from view.
        /// </summary>
        /// <returns></returns>
        private forum GetForumObjectFromView()
        {
            forum forumTmp = new forum();
            /*
            forumTmp.description = view.ForumDescription;
            forumTmp.name = view.ForumName;
			*/
            //tmp user id - nie tak, tak nie dziala wlasnie, trzea podac obiekt a nie id obiektu
			//w zasadzie nigdy sie nie dowiedzialem dlaczego... ale tak niestety jest czyli: zobacz w Tasku!
            //forumTmp.user_id = ContentNamesGlobals.TmpUserId;


            return forumTmp;
        }

        #endregion Private Methods
		}
	}
